#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=libcupsfilters2_lede
PKG_VERSION:=2.1.0
PKG_RELEASE:=1

PKG_SOURCE_NAME:=libcupsfilters

PKG_MAINTAINER:=Joynine <joynine@126.com>
PKG_SOURCE:=$(PKG_SOURCE_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/OpenPrinting/libcupsfilters/archive/refs/tags/$(PKG_VERSION).tar.gz
PKG_HASH:=skip

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_NAME)-$(PKG_VERSION)

PKG_FIXUP:=autoreconf
PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1

TARGET_LDFLAGS+=-Wl,-rpath-link=$(STAGING_DIR)/usr/lib $(if $(INTL_FULL),-lintl)

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk

define Package/libcupsfilters2_lede
  SECTION:=utils
  CATEGORY:=Printing
  SUBMENU:=Utilities
  TITLE:=(LEDE) OpenPrinting CUPS filters
      DEPENDS:=+libstdcpp +cups_lede +libcupsimage_lede +fontconfig +libexif +libtiff \
      +libjpeg +libpng +qpdf_lede +libpcre2 +glib2 +libfreetype $(INTL_DEPENDS) \
      +CUPS_FILTER_PDF_GS_LEDE:lcms2_lede \
      +CUPS_FILTER_PDF_POPPLER_LEDE:poppler_lede \
      +CUPS_FILTER_PDF_MUPDF_LEDE:mupdf_lede
  URL:=http://www.openprinting.org
endef

define Package/libcupsfilters2_lede/description
	CUPS filters maintained by OpenPrinting.
	The CUPS Filters package contains backends, filters and other software that was once part of the core CUPS distribution but is no longer maintained by Apple Inc.
endef


define Package/libcupsfilters2_lede/config
choice CUPS_FILTER_PDF_BACKEND_LEDE
	depends on PACKAGE_openprinting-cups-filters
	bool "PDF backend for raster conversion"
	default CUPS_FILTER_PDF_GS_LEDE

config CUPS_FILTER_PDF_GS_LEDE
	bool "Ghostscript: gstoraster"
	help
	 Ghostscript requires more storage but much less memory than poppler.

config CUPS_FILTER_PDF_POPPLER_LEDE
	bool "Poppler: pdftoraster"
	help
	 Popper requires less storage but consumes at lot of memory
	 with big documents.

config CUPS_FILTER_PDF_MUPDF_LEDE
	bool "MuPDF: mupdftoraster"

endchoice
endef

EXTRA_CFLAGS+= \
	-DPOINTERHOLDER_TRANSITION=0 \
	-Wno-deprecated-declarations

CONFIGURE_ARGS += \
	--disable-dbus \
	--disable-avahi \
	--disable-exif \
	--disable-ldap \
	--with-pdftops=hybrid \
	--enable-imagefilters \
	UNAME="Linux" \
	LIBS="$(TARGET_LDFLAGS)" \
	--$(if $(CONFIG_CUPS_FILTER_PDF_GS_LEDE),enable,disable)-ghostscript \
	$(if $(CONFIG_CUPS_FILTER_PDF_GS_LEDE),--with-gs-path=/usr/bin/gs,) \
	\
	--$(if $(CONFIG_CUPS_FILTER_PDF_POPPLER_LEDE),enable,disable)-poppler \
	\
	--$(if $(CONFIG_CUPS_FILTER_PDF_MUPDF_LEDE),enable,disable)-mutool \
	$(if $(CONFIG_CUPS_FILTER_PDF_MUPDF_LEDE),--with-mutool-path=/usr/bin/mutool,)


define Package/libcupsfilters2_lede/install
	$(INSTALL_DIR) $(1)/usr/lib/cups/driver
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/.libs/driverless $(1)/usr/lib/cups/driver
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/
endef

define Package/postinst
#!/bin/sh
[ -z "$$$${IPKG_INSTROOT}" ] && /etc/init.d/cupsd restart
endef

$(eval $(call BuildPackage,libcupsfilters2_lede))


